home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
TEMP
/
GNU
/
bison
/
TokenDecl
< prev
next >
Wrap
Text File
|
1995-06-28
|
2KB
|
52 lines
Token Decl
Previous: <Declarations=>Declaratio> * Next: <Precedence Decl=>Precedence> * Up: <Declarations=>Declaratio>
#Wrap on
{fH4}Token Type Names{f}
The basic way to declare a token type name (terminal symbol) is as follows:
#Wrap off
#fCode
%token {fStrong}name{f}
#f
#Wrap on
Bison will convert this into a {fCode}\#define{f} directive in
the parser, so that the function {fCode}yylex{f} (if it is in this file)
can use the name {fStrong}name{f} to stand for this token type's code.
Alternatively, you can use {fCode}%left{f}, {fCode}%right{f}, or {fCode}%nonassoc{f}
instead of {fCode}%token{f}, if you wish to specify precedence.
\*Note <Precedence Decl=>Precedence>: Operator Precedence.
You can explicitly specify the numeric code for a token type by appending
an integer value in the field immediately following the token name:
#Wrap off
#fCode
%token NUM 300
#f
#Wrap on
It is generally best, however, to let Bison choose the numeric codes for
all token types. Bison will automatically select codes that don't conflict
with each other or with ASCII characters.
In the event that the stack type is a union, you must augment the
{fCode}%token{f} or other token declaration to include the data type
alternative delimited by angle-brackets (\*Note <Multiple Types=>MultipleTy>: More Than One Value Type).
For example:
#Wrap off
#fCode
%union \{ \/\* define stack type \*\/
double val;
symrec \*tptr;
\}
%token <val> NUM \/\* define token NUM and its type \*\/
#f
#Wrap on